/*********************************************************************************
*            (c) Copyright,Shenzhen Smart Drone UAV Co., Ltd.  
*                        All Rights Reserved  
* 
* File 	 : uartchn.c
* By  	 : hirsi
* Date	 :2019-08-03 09:46:31
* Other	 : 
*  
**********************************************************************************/
#include "sys.h"

#define UART_TXFIFO_SIZE			1024


static FIFO u_txfifo; //,u_rxfifo;
static INT8U utxbuf[256];
void uartchn_sendloop (void)
{
	INT8U len;

	if (ReadFIFO(&u_txfifo, &len) == false) return;		
	if (ReadFIFOs(&u_txfifo, utxbuf, len) == false) return;		

	uart_writemass(USART_CTL, utxbuf, len);
}

//void uartchn_sendfifo(INT8U *data, INT8U len, INT8U needack)
void uartchn_sendfifo(INT8U *data, INT8U len)

{
    if (len == 0) return;
 	    
    WriteFIFO(&u_txfifo, len);
	//WriteFIFO(&u_txfifo, needack);
    WriteFIFOs(&u_txfifo, data, len);
}

void uartchn_setup (INT32U baud, INT16U txsize, INT16U rxsize)
{
	INT8U *ptr;

    if ((ptr = (INT8U *)mem_malloc(UART_TXFIFO_SIZE)) == NULL){
        return;
    }        
    InitFIFO(&u_txfifo, ptr, UART_TXFIFO_SIZE);

	uart_setup(USART_CTL, baud, txsize, rxsize);
}


